# -*- coding: utf-8 -*-
"""
Created on Tue Sep 20 13:42:34 2022

@author: obiri
"""

import mpctools as mpc
import casadi
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import time
import sys

font = {'family' : 'monospace', 'weight' : 'bold', 'size'   : 18}
mpl.rc('font', **font)  # pass in the font dict as kwargs
mpl.rcParams['axes.linewidth'] = 3.0
 

Delta = 60 # Time step
Nsim = 50
tplot = np.arange(Nsim+1)*Delta 


estimate_case1 = np.load('x_hat_C1.npy' )
estimate_case2 = np.load('x_hat_C2.npy' )
estimate_case3 = np.load('x_hat_C3.npy' )
actual_trajectories = np.load('p_true.npy' )






# ##------------------------------ploting on the same graph-------------------------------------------##

# fig_3, axs = plt.subplots(5, figsize=(18,12))

fig_3, axs = plt.subplots(5, figsize=(18,10))
axs[0].plot(tplot[:-8], actual_trajectories[:-7,0], 'r', linewidth=3)
axs[0].plot(tplot[:-8], estimate_case2[:-7,29], ':k' , linewidth=3)
axs[0].plot(tplot[:-8], estimate_case3[:-7,16], '--g' , linewidth=3)
axs[0].set_ylabel('Q$_{mabx}^{max}$(mg/Cell/min)', weight='bold', family='monospace', size=13, labelpad=5)
axs[0].set_xlim([0, 2000])
# axs[0].legend(['Actual', 'Case2', 'Case3'], ncol=3)
axs[0].grid(linewidth=0.5, linestyle='-.')

axs[1].plot(tplot[:-8], actual_trajectories[:-7,1], 'r',linewidth=3)
axs[1].plot(tplot[:-8], estimate_case2[:-7,16], ':k', linewidth=3)
axs[1].plot(tplot[:-8], estimate_case3[:-7,17], '--g', linewidth=3)
axs[1].set_ylabel('K$_{damm}$(mM)', weight='bold', family='monospace', size=16, labelpad=5)
axs[1].set_xlim([0, 2000])
# axs[1].legend(['Actual', 'Case2', 'Case3'], ncol=3)
axs[1].grid(linewidth=0.5, linestyle='-.')

axs[2].plot(tplot[:-8], actual_trajectories[:-7,2], 'r',linewidth=3)
axs[2].plot(tplot[:-8], estimate_case2[:-7,31], ':k', linewidth=3)
axs[2].plot(tplot[:-8], estimate_case3[:-7,18], '--g', linewidth=3)
axs[2].set_ylabel(r"$\rho$(g/L)", weight='bold', family='monospace', size=15, labelpad=5)
axs[2].set_xlim([0, 2000])
# axs[2].legend(['Actual', 'Case2', 'Case3'], ncol=3)
axs[2].grid(linewidth=0.5, linestyle='-.')

axs[3].plot(tplot[:-8], actual_trajectories[:-7,3], 'r', linewidth=3)
axs[3].plot(tplot[:-8], estimate_case2[:-7,28], ':k' , linewidth=3)
axs[3].plot(tplot[:-8], estimate_case3[:-7,19], '--g' , linewidth=3)
axs[3].set_ylabel('$\mu_{dmax}$', weight='bold', family='monospace', size=16, labelpad=5)
axs[3].set_xlim([0, 2000])
# axs[3].legend(['Actual', 'Case2', 'Case3'], ncol=3)
axs[3].grid(linewidth=0.5, linestyle='-.')

axs[4].plot(tplot[:-8], actual_trajectories[:-7,4], 'r', linewidth=3)
axs[4].plot(tplot[:-8], estimate_case2[:-7,19], ':k' , linewidth=3)
axs[4].plot(tplot[:-8], estimate_case3[:-7,20], '--g' , linewidth=3)
axs[4].set_ylabel('K$_{gln}$(mM)', weight='bold', family='monospace', size=16, labelpad=5)
axs[4].set_xlim([0, 2000])
# axs[4].legend(['Actual', 'Case2', 'Case3'], ncol=3)
axs[4].grid(linewidth=0.5, linestyle='-.')



fig_3.legend(['Actual', 'Case2', 'Case3'], ncol=3, loc='upper center',frameon=False)
plt.xlabel('Time(min)', weight='bold', family='monospace', size=15, labelpad=9)
fig_3.tight_layout()
plt.show()
plt.savefig('test.pdf')













